package com.cordys.opensource.crom.sql;

import com.cordys.cpc.bsf.busobject.QueryObject;
import com.cordys.cpc.bsf.classinfo.AttributeInfo;
import com.cordys.opensource.crom.BusObjectHelper;

class XQYParameter
{
	private final Column column;
	private final Object value;
	private String parameterName;
	
	XQYParameter(Column column, Object value)
	{
		this.column = column;
		this.value = value;
		column.getQuery().addXQYParameter(this);
	}
	
	Column getColumn()
	{
		return column;
	}
	
	Object getValue()
	{
		return value;
	}
	
	void addToQueryObject(QueryObject query)
	{
		String tableName = column.getTable().getTableName();
		AttributeInfo attribute = column.getAttributeInfo();
		String columnName = attribute.getColumnName();
		query.addParameter(getParameterName(), tableName + "." + columnName, BusObjectHelper.getQueryParameterType(attribute), value);
	}

	void setParameterName(String parameterName)
	{
		this.parameterName = parameterName;
	}
	
	String getParameterName()
	{
		return column.getQuery().getXQYParameterNamePrefix()+parameterName;
	}
	
	public String toString()
	{
		return ":"+getParameterName();
	}
}
